<template>
	<view>
		<view class="good_list">
			<view v-for="good in goodslist" :key="good.goods_id" @click="goodetail(good.goods_id)">
			<my-goodslist :good='good'></my-goodslist>	
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				quertlist:{
					query:'',
					cid:'',
					pagenum:1,
					pagesize:20
				},
				goodslist:[],
				total:0,
				// 节流阀
				isloading:false
			};
		},
		onLoad(options){
			this.quertlist.query=options.query||''
			this.quertlist.cid=options.cid||''
			this.getGoodslist()
			
	
		},
		onHide() {
			this.quertlist.query=''
			this.quertlist.cid=''
		},
		methods:{
			getGoodslist(){
				this.isloading=true
				this.request({
					url:`/public/v1/goods/search`,
					data:this.quertlist
				}).then(({data:res})=>{
					console.log(res)
					this.isloading=false
					this.goodslist=[...this.goodslist,...res.message.goods]
					this.total=res.message.total
					uni.stopPullDownRefresh()
				})
			},
			goodetail(id){
				uni.navigateTo({
					url:`/subpkg/goods_detail/goods_detail?goods_id=${id}`
				})
			},
		},
		// 上拉触底事件
		onReachBottom() {
			if(this.isloading){
				return
			}else{
				if(this.quertlist.pagenum<this.toltalpa){
					this.quertlist.pagenum++
					this.getGoodslist()
				}else{
					return 
				}
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.quertlist.pagenum=1
			this.goodslist=[]
			this.total=0
			this.isloading=false
			this.getGoodslist()
		},
		computed:{
			toltalpa(){
				return Math.ceil(this.total/this.quertlist.pagesize)
			}
		}
	}
</script>

<style lang="scss">

</style>
